package com.inspectortime.domain.impl;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

import org.hibernate.annotations.Index;

import com.inspectortime.common.PersistentEntityBase;
import com.inspectortime.domain.ZipCodeGeoData;
import com.inspectortime.service.ZipCodeInfo;
import com.inspectortime.service.ZipCodeUtils;

@Entity
@Table(name = "ZIP_CODE_GEO_DATA")
public class ZipCodeGeoDataImpl extends PersistentEntityBase implements ZipCodeGeoData {

	private String zipCode;
	private String city;
	private double latitude;
	private double longitude;
	private String stateCode;
	private String stateName;
	private String countyCode;
	private String countyName;
	
	public ZipCodeGeoDataImpl() {
	}
	
	public ZipCodeGeoDataImpl(ZipCodeInfo info) {
		this.zipCode = info.getZipCode();
		this.city = info.getCity();
		this.latitude = info.getLatitude();
		this.longitude = info.getLongitude();
		this.countyCode = info.getCountyCode();
		this.countyName = info.getCountyName();
		this.stateCode = info.getStateCode();
		this.stateName = info.getStateName();
	}
	
	public ZipCodeGeoDataImpl(String zipCode) {
		this.zipCode = zipCode;
	}
	
	@Column(length=100)
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	
	@Column(length=3)
	public String getCountyCode() {
		return countyCode;
	}
	public void setCountyCode(String countyCode) {
		this.countyCode = countyCode;
	}
	
	@Column(length=100)
	public String getCountyName() {
		return countyName;
	}
	public void setCountyName(String countyName) {
		this.countyName = countyName;
	}
	
	@Index(name="latitudeIndex")
	public double getLatitude() {
		return latitude;
	}
	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}
	
	@Index(name="longitudeIndex")
	public double getLongitude() {
		return longitude;
	}
	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}
	
	@Column(length=2)
	public String getStateCode() {
		return stateCode;
	}
	public void setStateCode(String stateCode) {
		this.stateCode = stateCode;
	}
	
	@Column(length=30)
	public String getStateName() {
		return stateName;
	}
	public void setStateName(String stateName) {
		this.stateName = stateName;
	}
	
	@Column(unique=true, length=5)
	@Index(name="zipCodeIndex")
	public String getZipCode() {
		return zipCode;
	}
	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}
	
	public double distanceTo(ZipCodeGeoData otherZipCode) {
		return ZipCodeUtils.calculateDistance(this.getLatitude(), this.getLongitude(), otherZipCode.getLatitude(), otherZipCode.getLongitude());
	}
	 
}
